//
//  RecentView.m
//  YiShangPin
//
//  Created by 衣尚品1 on 15/3/16.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "RecentView.h"
#import "AppDelegate.h"

@implementation RecentView{
    AppDelegate *delegate;
    CGContextRef context;
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    //创建画布
    context = UIGraphicsGetCurrentContext();
    //设置线条颜色
    [[UIColor grayColor] set];
    //设置线条宽度
    CGContextSetLineWidth(context, 0.3f);
    
    delegate.isHaveHeight = NO;
    [self addView2];
    
    CGContextStrokePath(context);
}

- (float)addView2{

    delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    UIFont *lableFont = [UIFont fontWithName:@"TimesNewRomanPS-ItalicMT" size:16];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    image.image = [UIImage imageNamed:@"reviewDetails.png"];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 150, 18)];
    label1.text = @"Recent Reviews";
    label1.font = lableFont;
    label1.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldItalicMT" size:18];
    
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(delegate.width-80, 0, 80, 18)];
    [button setTitle:@"View All" forState:0];
    button.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [button setTitleColor:[UIColor colorWithRed:47.f/255 green:164.f/255 blue:230.f/255 alpha:1] forState:0];
    
    UIImageView *starImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 25, 150, 20)];
    starImage.image = [UIImage imageNamed:@"star.png"];
    
    UILabel *reviewLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 55, 350, 50)];
    reviewLabel.text = @"\"Came so quick compared to the other things I ordered,but I love it nice material.\"";
    reviewLabel.font = lableFont;
    
    reviewLabel.numberOfLines = 0;
    //    lable4.lineBreakMode = NSLineBreakByTruncatingTail;
    reviewLabel.lineBreakMode = NSLineBreakByWordWrapping;
    CGSize size = [reviewLabel.text boundingRectWithSize:CGSizeMake(delegate.width-60, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:reviewLabel.font,NSFontAttributeName, nil] context:nil].size;
    reviewLabel.frame = CGRectMake(20, 55, delegate.width-60, size.height);
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, delegate.width-20, 50)];
    nameLabel.text = @"Rebecca Sowash";
    nameLabel.font = lableFont;
    
    nameLabel.numberOfLines = 0;
    
    nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    CGSize size1 = [nameLabel.text boundingRectWithSize:CGSizeMake(nameLabel.frame.size.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:nameLabel.font,NSFontAttributeName, nil] context:nil].size;
    nameLabel.frame = CGRectMake(20, 60+size.height, size1.width, size1.height);
    nameLabel.textColor = [UIColor grayColor];
    
    if (delegate.isHaveHeight == NO) {
        [self addSubview:image];
        [self addSubview:label1];
        [self addSubview:button];
        [self addSubview:starImage];
        [self addSubview:reviewLabel];
        [self addSubview:nameLabel];
    }
    
    float viewHeight = image.frame.size.height + 60+size.height + size1.height;
    return viewHeight;

}

@end
